<!DOCTYPE html>
<html>
   <head>
      <title>完工报工单</title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0 Access-Control-Allow-Origin">
      <!-- 引入 Bootstrap -->
      <!--<link href="<?=base_url('html/bootstrap_v3/css/bootstrap.css')?>" rel="stylesheet">-->
      <link href="<?=  base_url('/html/bootstrap_v3/css/bootstrap.css')?>" rel="stylesheet">
      <link href="<?=base_url('html/bootstrap_v3/datepicker/css/bootstrap-datetimepicker.min.css')?>" rel="stylesheet">
      <script src="<?=base_url('html/js/jquery-1.8.3.min.js')?>"></script>
      <script src="<?=base_url('html/bootstrap_v3/js/bootstrap.min.js')?>"></script>
      <script src="<?=base_url('html/bootstrap_v3/datepicker/js/bootstrap-datetimepicker.js')?>"></script>
      <script src="<?=base_url('html/bootstrap_v3/datepicker/js/locales/bootstrap-datetimepicker.zh-CN.js')?>"></script>
      <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
      <script type="text/javascript">
          $(document).ready(function(){
              $("#finish").click(function(){
                  window.location.href = "<?=  base_url('baogongFinish')?>"
              });
              $("#check").click(function(){
                 window.location.href = "<?=  base_url('baogongCheck')?>"
              });
          })
      </script> 
     
      <!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
      <!-- 注意： 如果通过 file://  引入 Respond.js 文件，则该文件无法起效果 -->
      <!--[if lt IE 9]>
         <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
         <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
      <![endif]-->
   </head>
   <body>
       <input type="text" name="UserName" id="UserName" value="<?=$username?>" style="display:none">
       <input type="text" name="UserNo" id="UserNo" value="<?=$userno?>" style="display:none">
       <?php if($type=="WGHB") :?>
                <div class="container">
                 <fieldset>
                   <legend class="text-center" style="font-weight:bold;font-size:2em;">
                     完工报工信息
                   </legend>
                     <?php if(isset($resDate[0]['产品代号'])):?>
                         <table class="table  table-bordered">
                             <tbody>
                                 <tr>
                                     <td>流转卡号</td>
                                     <td><?=$resDate[0]['流转卡号']?></td>
                                  </tr>
                                  <tr>
                                     <td>派工单号</td>
                                     <td><?=$resDate[0]['派工单号']?></td>
                                  </tr>
                                  <tr>
                                     <td>工艺路线</td>
                                     <td><?=$resDate[0]['工艺路线']?></td>
                                  </tr>
                                  <tr>
                                     <td>产品代号</td>
                                     <td><?=$resDate[0]['产品代号']?></td>
                                  </tr>
                                  <tr>
                                     <td>产品名称</td>
                                     <td><?=$resDate[0]['产品名称']?></td>
                                  </tr>
                             </tbody>
                         </table>
                     <?php endif;?>
                     <div class="panel-group" id="accordion">
                         <?php foreach ($resDate as $value):?>
                         <div class="panel panel-default">
                           <div class="panel-heading">
                             <h4 class="panel-title">
                                 <label><input name="batch_wg" type="checkbox" value="<?=$value['工序号']?>@#<?=$value['流转卡号']?>@#<?=$value['派工单号']?>@#<?=$value['工序代码']?>@#<?=$value['工站名称']?>" /></label> 
                               <a data-toggle="collapse" data-parent="#accordion" 
                                  href="#<?=$value['工序号']?>">
                                 工站名称：     <?=$value['工站名称']?> --- <?=$value['工序号']?> --- <?=$value['工序代码']?>
                               </a>
                             </h4>
                           </div>
                           <div id="<?=$value['工序号']?>" class="panel-collapse collapse">
                             <div class="panel-body">
                                     <table class="table  table-bordered">
                                         <tbody>
                                            <tr class="success">
                                               <td>工序代码</td>
                                               <td><?=$value['工序代码']?></td>
                                            </tr>
                                            <tr  class="danger">
                                               <td>流转卡数量</td>
                                               <td><?=$value['流转卡数量']?></td>
                                            </tr>
                                            <tr class="success">
                                               <td>良品量</td>
                                               <td><?=$value['良品量']?></td>
                                            </tr>
                                            <tr  class="danger">
                                               <td>不良品量</td>
                                               <td><?=$value['不良品量']?></td>
                                            </tr>
                                            <tr class="warning">
                                               <td>已汇报量</td>
                                               <td><?=$value['已汇报量']?></td>
                                            </tr>

                                         </tbody>
                                      </table>
                                 <!--
                                 <button onClick="getvalue('<?=$value["工序号"]?>','<?=$value['流转卡号']?>','<?=$value['派工单号']?>','<?=$value['工序代码']?>','<?=$value['工站名称']?>')" type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal" >
                                                     我要报工
                                      </button>-->
                             </div>
                           </div>
                         </div>
                         <?php endforeach; ?>
                     </div>
                     <p style="margin-top: 10px">
                        <button id="batch_wg" type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#myModal_batch">
                           多工序报工
                        </button>
                    </p>
                     <!-- 模态框（Modal） -->
                     <div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
                        aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                           <div class="modal-content">
                              <div class="modal-header">
                                 <button type="button" class="close" data-dismiss="modal" 
                                    aria-hidden="true">×
                                 </button>
                                 <h4 class="modal-title" id="myModalLabel">
                                    请输入报工数量
                                 </h4>
                              </div>
                              <div class="modal-body">
                                  <table>
                                      <tbody>
                                          <tr>
                                              <td>报工数量</td>
                                              <td><input type="text" name="num" id='num'></td>
                                          </tr>
                                          <tr>
                                              <td>报工人</td>
                                              <td><?=$username?></td>
                                          </tr>
                                      </tbody>
                                  </table>
                                  <input style='display: none' type="text" name="TaskOperNo" id='TaskOperNo' value=''>
                                  <input style='display: none' type="text" name="LZKNO" id='LZKNO' value=''>
                                  <input style='display: none' type="text" name="TaskBillNo" id='TaskBillNo' value=''>
                                  <input style='display: none' type="text" name="TaskOperNumber" id='TaskOperNumber' value=''>
                                  <input style='display: none' type="text" name="TaskOperName" id='TaskOperName' value=''>
                              </div>
                              <div class="modal-footer">
                                 <button type="button" class="btn btn-default" 
                                    data-dismiss="modal">
                                    关闭
                                 </button>
                                 <button type="button" class="btn btn-primary submitFinish">
                                    提交更改<!--完工汇报单个汇报-->
                                 </button>
                              </div>
                           </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                     </div><!-- /.modal -->
                     <!-- 模态框（Modal）多工序提交（完工） -->
                     <div class="modal fade" id="myModal_batch" tabindex="-1" role="dialog" 
                        aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                           <div class="modal-content">
                              <div class="modal-header">
                                 <button type="button" class="close" data-dismiss="modal" 
                                    aria-hidden="true">×
                                 </button>
                                 <h4 class="modal-title" id="myModalLabel">
                                    请输入报工数量(多工序报工)
                                 </h4>
                              </div>
                              <div class="modal-body">
                                  <table>
                                      <tbody>
                                          <tr>
                                              <td>良品数量</td>
                                              <td><input type="text" name="num_batch" id='num_batch'></td>
                                          </tr>
                                          <tr>
                                              <td>不良数量</td>
                                              <td><input type="text" name="badnum_batch" id='badnum_batch' readonly="readonly" value="0"></td>
                                          </tr>
                                          <tr>
                                              <td>报工人</td>
                                              <td><?=$username?></td>
                                          </tr>
                                      </tbody>
                                  </table>
                                  <div id="showwarning"></div>
                                  <div id="badreason"></div>
                                  <input type="hidden" id="badreasonjsonhtml">
                                  <input style='display: none' type="text" name="TaskOperNo" id='TaskOperNo' value=''>
                                  <input style='display: none' type="text" name="LZKNO" id='LZKNO' value=''>
                                  <input style='display: none' type="text" name="TaskBillNo" id='TaskBillNo' value=''>
                                  <input style='display: none' type="text" name="TaskOperNumber" id='TaskOperNumber' value=''>
                                  <input style='display: none' type="text" name="TaskOperName" id='TaskOperName' value=''>
                              </div>
                              <div class="modal-footer">
                                 <button type="button" class="btn btn-default" 
                                    data-dismiss="modal">
                                    关闭
                                 </button>
                                 <button type="button" class="btn btn-primary submitFinish_batch">
                                    提交更改
                                 </button>
                              </div>
                           </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                     </div><!-- /.modal -->
             </fieldset>
             </div>
       <?php elseif($type=="ZJHB"):?>
            <div class="container">
                 <fieldset>
                   <legend class="text-center" style="font-weight:bold;font-size:2em;">
                     质检报工信息
                   </legend>
                     <?php if(isset($resDate[0]['产品代号'])):?>
                         <table class="table  table-bordered">
                             <tbody>
                                 <tr>
                                     <td>产品代号</td>
                                     <td><?=$resDate[0]['产品代号']?></td>
                                  </tr>
                                  <tr>
                                     <td>产品名称</td>
                                     <td><?=$resDate[0]['产品名称']?></td>
                                  </tr>
                             </tbody>
                         </table>
                     <?php endif;?>
                     <div class="panel-group" id="accordion">
                         <?php foreach ($resDate as $value):?>
                         <div class="panel panel-default">
                           <div class="panel-heading">
                             <h4 class="panel-title">
                                 <!--
                                 <label><input name="batch_zj" type="checkbox" value="<?=$value['工序号']?>@#<?=$value['流转卡号']?>@#<?=$value['派工单号']?>@#<?=$value['工序代码']?>@#<?=$value['工站名称']?>" /></label>
                                 -->
                                 <a data-toggle="collapse" data-parent="#accordion" 
                                  href="#<?=$value['ShowId']?>">
                                 流转卡号：     <?=$value['流转卡号']?> --- <?=$value['工站名称']?>
                               </a>
                             </h4>
                           </div>
                           <div id="<?=$value['ShowId']?>" class="panel-collapse collapse">
                             <div class="panel-body">
                                     <table class="table  table-bordered">
                                         <tbody>
                                             
                                             <tr  class="active">
                                               <td>工艺路线</td>
                                               <td><?=$value['工艺路线']?></td>
                                            </tr>
                                            <tr class="success">
                                               <td>流转卡号</td>
                                               <td><?=$value['流转卡号']?></td>
                                            </tr>
                                            <tr class="danger">
                                               <td>派工单号</td>
                                               <td><?=$value['派工单号']?></td>
                                            </tr>
                                            <tr class="warning">
                                               <td>工序代码</td>
                                               <td><?=$value['工序代码']?></td>
                                            </tr>
                                            <tr  class="active">
                                               <td>流转卡数量</td>
                                               <td><?=$value['流转卡数量']?></td>
                                            </tr>
                                            <tr  class="success">
                                               <td>良品量</td>
                                               <td><?=$value['已汇报量']?></td>
                                            </tr>
                                            <tr  class="danger">
                                               <td>不良品量</td>
                                               <td><?=$value['不良品量']?></td>
                                            </tr>
                                         </tbody>
                                      </table>
                                      <button onClick="getvalue('<?=$value["工序号"]?>','<?=$value['流转卡号']?>','<?=$value['派工单号']?>','<?=$value['工序代码']?>','<?=$value['工站名称']?>')" type="button" class="btn btn-primary btn-block zhijiansubmit" data-toggle="modal" data-target="#myModal" >
                                                     我要报工
                                      </button>
                             </div>
                           </div>
                         </div>
                         <?php endforeach; ?>
                     </div>
                     <!--
                     <p style="margin-top: 10px">
                        <button id="batch_wg" type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#myModal_batch_check">
                           批量报工
                        </button>
                    </p>
                     -->
                     <!-- 模态框（Modal） -->
                     <div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
                        aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                           <div class="modal-content">
                              <div class="modal-header">
                                 <button type="button" class="close" data-dismiss="modal" 
                                    aria-hidden="true">×
                                 </button>
                                 <h4 class="modal-title" id="myModalLabel">
                                    请输入报工数量
                                 </h4>
                              </div>
                              <div class="modal-body">
                                  <table>
                                      <tbody>
                                          <tr>
                                              <td>良品数量</td>
                                              <td><input type="text" name="num" id='num'></td>
                                          </tr>
                                          <tr>
                                              <td>不良数量</td>
                                              <td><input type="text" name="badnum_batch" id='badnum_batch' readonly="readonly" value="0"></td>
                                          </tr>
                                          <tr>
                                              <td>报工人</td>
                                              <td><?=$username?></td>
                                          </tr>
                                      </tbody>
                                  </table>
                                  <div id="badreason"></div>
                                  <input type="hidden" id="badreasonjsonhtml">
                                  <input style='display: none' type="text" name="TaskOperNo" id='TaskOperNo' value=''>
                                  <input style='display: none' type="text" name="LZKNO" id='LZKNO' value=''>
                                  <input style='display: none' type="text" name="TaskBillNo" id='TaskBillNo' value=''>
                                  <input style='display: none' type="text" name="TaskOperNumber" id='TaskOperNumber' value=''>
                                  <input style='display: none' type="text" name="TaskOperName" id='TaskOperName' value=''>
                              </div>
                              <div class="modal-footer">
                                 <button type="button" class="btn btn-default" 
                                    data-dismiss="modal">
                                    关闭
                                 </button>
                                 <button type="button" class="btn btn-primary submitCheck">
                                    提交更改
                                 </button>
                              </div>
                           </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                     </div><!-- /.modal -->
                      <!-- 模态框（Modal）批量提交（质检） -->
                      <!--
                     <div class="modal fade" id="myModal_batch_check" tabindex="-1" role="dialog" 
                        aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                           <div class="modal-content">
                              <div class="modal-header">
                                 <button type="button" class="close" data-dismiss="modal" 
                                    aria-hidden="true">×
                                 </button>
                                 <h4 class="modal-title" id="myModalLabel">
                                    请输入报工数量(批量报工)
                                 </h4>
                              </div>
                              <div class="modal-body">
                                  <table>
                                      <tbody>
                                          <tr>
                                              <td>报工数量</td>
                                              <td><input type="text" name="num_batch" id='num_batch'></td>
                                          </tr>
                                          <tr>
                                              <td>报工人</td>
                                              <td><?=$username?></td>
                                          </tr>
                                      </tbody>
                                  </table>
                                  <input style='display: none' type="text" name="TaskOperNo" id='TaskOperNo' value=''>
                                  <input style='display: none' type="text" name="LZKNO" id='LZKNO' value=''>
                                  <input style='display: none' type="text" name="TaskBillNo" id='TaskBillNo' value=''>
                                  <input style='display: none' type="text" name="TaskOperNumber" id='TaskOperNumber' value=''>
                                  <input style='display: none' type="text" name="TaskOperName" id='TaskOperName' value=''>
                              </div>
                              <div class="modal-footer">
                                 <button type="button" class="btn btn-default" 
                                    data-dismiss="modal">
                                    关闭
                                 </button>
                                 <button type="button" class="btn btn-primary submitFinish_batch_check">
                                    提交更改
                                 </button>
                              </div>
                           </div>
                        </div>
                     </div>
                     -->
             </fieldset>
             </div>
       <?php elseif($type=="success"):?>
            <div style="margin-top: 80px;margin-left: 20px;margin-right: 20px">
                <p style="text-align:center;color: green;font-size: 16px;font-weight: bold;">
                    <?=$resMsg?>
                </p>
                <button type="button" class="btn btn-primary btn-block btn-lg returnHomePage" style="margin-top: 30px">
                                                     返回
                </button>
            </div>
       <?php elseif($type=="faild"):?>
            <div style="margin-top: 80px;margin-left: 20px;margin-right: 20px">
                <p style="text-align:center;color: red;font-size: 16px;font-weight: bold;">
                    <?=$resMsg?>
                </p>
                <button type="button" class="btn btn-primary btn-block btn-lg returnHomePage" style="margin-top: 30px">
                                                     返回
                </button>
            </div>
       <?php elseif($type=="empty"):?>
            <div style="margin-top: 80px;margin-left: 20px;margin-right: 20px">
                <p style="text-align:center;color: red;font-size: 16px;font-weight: bold;">
                    <?=$resMsg?>
                </p>
                <button type="button" class="btn btn-primary btn-block btn-lg returnHomePage" style="margin-top: 30px">
                                                     返回
                </button>
            </div>
       <?php endif;?>
   </body>
   <script type="text/javascript">
       function getvalue(TaskOperNo,LZKNO,TaskBillNo,TaskOperNumber,TaskOperName){
                    $("#TaskOperNo").val(TaskOperNo);
                    $("#LZKNO").val(LZKNO);
                    $("#TaskBillNo").val(TaskBillNo);
                    $("#TaskOperNumber").val(TaskOperNumber);
                    $("#TaskOperName").val(TaskOperName);
                    //alert("你选择的工序是"+TaskOperNo+"，你选择的流转卡号是"+LZKNO+",你选择的派工单号是"+TaskBillNo+",你选择的工序代码是"+TaskOperNumber+",你选择的工站名称是"+TaskOperName);
             }
             function badnumtotal(){
                 //console.log("data = " + this.value);
                var LZNum = <?=$LZNum;?>;
                //console.log("LZNum = " + LZNum);
                var totalRow = 0; 
                var countnums;
                var badreasonjsonhtml = "";
                $('#badreason tr').each(function() { 
                    $(this).find('td:eq(2) input').each(function(){ 
                        if($(this).val() == ''){
                            countnums = 0;
                        }else{
                            countnums = $(this).val();
                            badreasonjsonhtml = badreasonjsonhtml+"{'代码':'"+$("td:eq(0)",$(this).parent().parent()).text()+"','名称':'"+$("td:eq(1)",$(this).parent().parent()).text()+"','不良数量':'"+$(this).val()+"'},";
                            //console.log("代码 = " + $("td:eq(0)",$(this).parent().parent()).text());
                            //console.log("名称 = " + $("td:eq(1)",$(this).parent().parent()).text());
                            //console.log("不良数量 = "+ $(this).val());
                        }
                        totalRow += parseFloat(countnums); 
                    }); 
                }); 
                badreasonjsonhtml = badreasonjsonhtml.substr(0,badreasonjsonhtml.length-1);
                badreasonjsonhtml = "{'M_QS':["+badreasonjsonhtml+"]}";
                //console.log("badreasonjsonhtml = "+badreasonjsonhtml);
                $("#badreasonjsonhtml").val(badreasonjsonhtml);
                $("#badnum_batch").val(totalRow);
                //var liangNum = LZNum - totalRow;
               // console.log("liangNum"+liangNum);
                $("#num_batch").val(LZNum - totalRow);
                
             }
             
             $(document).ready(function(){
                 //完工汇报多工序汇报
                 $("#batch_wg").click(function(){
                     var strOperNumber = "";
                     var alertStr = "您选择的多道工序分别是：<br>";
                     $("input[name='batch_wg']:checkbox").each(function(){ 
                        if($(this).attr("checked")){
                            var strs= new Array();
                            strs = $(this).val().split("@#");
                            //batchSubmit(strs[0],strs[1],strs[2],strs[3],strs[4]);
                            alertStr = alertStr + "<b style='color:red;'>" + strs[0] + "(" + strs[4] + "),</b><br>";
                            strOperNumber += strs[3]+",";
                        }
                    });
                    strOperNumber = strOperNumber.substr(0,strOperNumber.length-1);
                    if(strOperNumber.length > 0){
                        $.ajax({
                            type:"GET",
                            url:'<?=base_url("baogong/getBadReasonByJson?strOperNumber=")?>'+strOperNumber,
                            dataType: "json",
                            success:function(data){
                                
                                var addHtml = "<table id='badreason' class='table' width='100%'>\n\
                                                <thead>\n\
                                                    <tr>\n\
                                                        <th width='20%'>代码</th>\n\
                                                        <th width='50%'>名称</th>\n\
                                                        <th width='30%'>不良数量</th>\n\
                                                    </tr>\n\
                                                </thead>\n\
                                                <tbody>";
                                for(i in data.M_BadReason){
                                    addHtml = addHtml + "<tr><td width='20%'>"+data.M_BadReason[i]['代码']+"</td><td width='50%'>"+data.M_BadReason[i]['名称']+"</td><td width='30%'><input style='width:80%' type='number' name='num_"+data.M_BadReason[i]['代码']+"' onchange='badnumtotal()'></td></tr>";
                                }
                                addHtml = addHtml + "</tbody></table>";
                                $("#badreason").html(addHtml);
                                // window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                        alert(XMLHttpRequest.status);
                                        alert(XMLHttpRequest.readyState);
                                        alert(textStatus);
                                        alert("您输入的信息有误，请重新确认或联系管理员！");
                            }
                        });
                    }
                    alertStr = alertStr + "请仔细检查，确认您选择的工序进行报工！";
                    $("#showwarning").html(alertStr);
                 })
                 //多工序报公提交(无不良数量)
                 /*
                 $(".submitFinish_batch").click(function(){
                     var TaskOperNo_arr = new Array();      //工序号
                     var TaskOperNumber_arr = new Array();  //工序代码
                     var TaskOperName_arr = new Array();;   //工站名称
                     var i= 0;
                     var LZKNO;       //流转卡号
                     var TaskBillNo;  //派工单号
                    $("input[name='batch_wg']:checkbox").each(function(){ 
                        if($(this).attr("checked")){
                            
                            
                            var strs= new Array();
                            strs = $(this).val().split("@#");
                            TaskOperNumber_arr[i]   = strs[3];//工序代码
                            TaskOperNo_arr[i]       = strs[0];//工序号
                            TaskOperName_arr[i]     = strs[4];//工站名称
                            LZKNO = strs[1];
                            TaskBillNo = strs[2];
                            i = i+1;
                            //batchSubmit(strs[0],strs[1],strs[2],strs[3],strs[4]);
                        }
                    })
                    var json_TaskOperNo       = JSON.stringify(TaskOperNo_arr);
                    var json_TaskOperNumber   = JSON.stringify(TaskOperNumber_arr);
                    var json_TaskOperName     = JSON.stringify(TaskOperName_arr);
                    
                    var UserName = $("#UserName").val();
                    var UserNo   = $("#UserNo").val();
                    var FQty     = $("#num_batch").val();
                    if(!isNaN(FQty)){
                       $.ajax({
                           type:"GET",
                           url:'<?=base_url("baogongFinish/TaskSubmitMultiByJSON?json_TaskOperNo=")?>'+json_TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&json_TaskOperNumber="+json_TaskOperNumber+"&json_TaskOperName="+json_TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=WGHB&FQty="+FQty,
                           dataType: "json",
                           success:function(data){
                                window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                           },
                           error: function(XMLHttpRequest, textStatus, errorThrown) {
                                       alert(XMLHttpRequest.status);
                                       alert(XMLHttpRequest.readyState);
                                       alert(textStatus);
                                       alert("您输入的信息有误，请重新确认或联系管理员！");
                           }
                       })
                   }else{
                       $("#num").val(''); 
                       alert("请您输入正确的报工数字！");
                   }
                    
                 })
                 */
                 //多工序报公(有不良数量)
                 $(".submitFinish_batch").click(function(){
                     var TaskOperNo_arr = new Array();      //工序号
                     var TaskOperNumber_arr = new Array();  //工序代码
                     var TaskOperName_arr = new Array();;   //工站名称
                     var i= 0;
                     var LZKNO;       //流转卡号
                     var TaskBillNo;  //派工单号
                    $("input[name='batch_wg']:checkbox").each(function(){ 
                        if($(this).attr("checked")){
                            
                            
                            var strs= new Array();
                            strs = $(this).val().split("@#");
                            TaskOperNumber_arr[i]   = strs[3];//工序代码
                            TaskOperNo_arr[i]       = strs[0];//工序号
                            TaskOperName_arr[i]     = strs[4];//工站名称
                            LZKNO = strs[1];
                            TaskBillNo = strs[2];
                            i = i+1;
                            //batchSubmit(strs[0],strs[1],strs[2],strs[3],strs[4]);
                        }
                    })
                    var json_TaskOperNo       = JSON.stringify(TaskOperNo_arr);
                    var json_TaskOperNumber   = JSON.stringify(TaskOperNumber_arr);
                    var json_TaskOperName     = JSON.stringify(TaskOperName_arr);
                    
                    var UserName = $("#UserName").val();
                    var UserNo   = $("#UserNo").val();
                    var FQty     = $("#num_batch").val();
                    var BadNum   = $("#badnum_batch").val();
                    
                    //异常数量json字符串
                    var badreasonjsonhtml = $("#badreasonjsonhtml").val();
                    //console.log('<?=base_url("baogongFinish/TaskQSSubmitByJSONMobile?json_TaskOperNo=")?>'+json_TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&json_TaskOperNumber="+json_TaskOperNumber+"&json_TaskOperName="+json_TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=WGHB&FQty="+FQty+"&badreasonjsonhtml="+badreasonjsonhtml+"&BadNum="+BadNum);
                    if(!isNaN(FQty)){
                       $.ajax({
                           type:"GET",
                           url:'<?=base_url("baogongFinish/TaskQSSubmitByJSONMobile?json_TaskOperNo=")?>'+json_TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&json_TaskOperNumber="+json_TaskOperNumber+"&json_TaskOperName="+json_TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=WGHB&FQty="+FQty+"&badreasonjsonhtml="+badreasonjsonhtml+"&BadNum="+BadNum,
                           dataType: "json",
                           success:function(data){
                               //console.log(data);
                                window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                           },
                           error: function(XMLHttpRequest, textStatus, errorThrown) {
                                       alert(XMLHttpRequest.status);
                                       alert(XMLHttpRequest.readyState);
                                       alert(textStatus);
                                       alert("您输入的信息有误，请重新确认或联系管理员！");
                           }
                       });
                   }else{
                       $("#num").val(''); 
                       alert("请您输入正确的报工数字！");
                   }
                    
                 })
                 
                 /*
                 //质检汇报多工序汇报
                 $(".submitFinish_batch_check").click(function(){
                     var TaskOperNo_arr = new Array();      //工序号
                     var TaskOperNumber_arr = new Array();  //工序代码
                     var TaskOperName_arr = new Array();;   //工站名称
                     var i= 0;
                     var LZKNO;       //流转卡号
                     var TaskBillNo;  //派工单号
                    $("input[name='batch_zj']:checkbox").each(function(){ 
                        if($(this).attr("checked")){
                            
                            
                            var strs= new Array();
                            strs = $(this).val().split("@#");
                            TaskOperNumber_arr[i]   = strs[3];//工序代码
                            TaskOperNo_arr[i]       = strs[0];//工序号
                            TaskOperName_arr[i]     = strs[4];//工站名称
                            LZKNO = strs[1];
                            TaskBillNo = strs[2];
                            i = i+1;
                            //batchSubmit(strs[0],strs[1],strs[2],strs[3],strs[4]);
                        }
                    })
                    var json_TaskOperNo       = JSON.stringify(TaskOperNo_arr);
                    var json_TaskOperNumber   = JSON.stringify(TaskOperNumber_arr);
                    var json_TaskOperName     = JSON.stringify(TaskOperName_arr);
                    
                    var UserName = $("#UserName").val();
                    var UserNo   = $("#UserNo").val();
                    var FQty     = $("#num_batch").val(); 
                    if(!isNaN(FQty)){
                       $.ajax({
                           type:"GET",
                           url:'<?=base_url("baogongFinish/TaskSubmitMultiByJSON?json_TaskOperNo=")?>'+json_TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&json_TaskOperNumber="+json_TaskOperNumber+"&json_TaskOperName="+json_TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=ZJHB&FQty="+FQty,
                           dataType: "json",
                           success:function(data){
                                window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                           },
                           error: function(XMLHttpRequest, textStatus, errorThrown) {
                                       alert(XMLHttpRequest.status);
                                       alert(XMLHttpRequest.readyState);
                                       alert(textStatus);
                                       alert("您输入的信息有误，请重新确认或联系管理员！");
                           }
                       })
                   }else{
                       $("#num").val(''); 
                       alert("请您输入正确的报工数字！");
                   }
                    
                 })
                 */
                 //质检汇报点击我要报工后带出不良原因界面
                 $(".zhijiansubmit").click(function(){
                    var strOperNumber = $("#TaskOperNumber").val();
                    //console.log("strOperNumber = " + strOperNumber);
                    strOperNumber = strOperNumber.substr(0,strOperNumber.length-1);
                    if(strOperNumber.length > 0){
                        $.ajax({
                            type:"GET",
                            url:'<?=base_url("baogong/getBadReasonByJson?strOperNumber=")?>'+strOperNumber,
                            dataType: "json",
                            success:function(data){
                                    //console.log("new data = " + data);
                                var addHtml = "<table id='badreason' class='table'>\n\
                                                <thead>\n\
                                                    <tr>\n\
                                                        <th>代码</th>\n\
                                                        <th>名称</th>\n\
                                                        <th>不良数量</th>\n\
                                                    </tr>\n\
                                                </thead>\n\
                                                <tbody>";
                                for(i in data.M_BadReason){
                                    addHtml = addHtml + "<tr><td>"+data.M_BadReason[i]['代码']+"</td><td>"+data.M_BadReason[i]['名称']+"</td><td><input type='number' name='num_"+data.M_BadReason[i]['代码']+"' onchange='badnumtotal()'></td></tr>";
                                }
                                addHtml = addHtml + "</tbody></table>";
                                $("#badreason").html(addHtml);
                                // window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                        alert(XMLHttpRequest.status);
                                        alert(XMLHttpRequest.readyState);
                                        alert(textStatus);
                                        alert("您输入的信息有误，请重新确认或联系管理员！");
                            }
                        });
                    }
                 })
                 //完工汇报单个汇报
                $(".submitFinish").one("click",function(){
                    var TaskOperNo     = $("#TaskOperNo").val();
                    var LZKNO          = $("#LZKNO").val();
                    var TaskBillNo     = $("#TaskBillNo").val();
                    var TaskOperNumber = $("#TaskOperNumber").val();
                    var TaskOperName   = $("#TaskOperName").val();
                    var UserName       = $("#UserName").val();
                    var UserNo         = $("#UserNo").val();
                    var FQty           = $("#num").val(); 
                    if(!isNaN(FQty)){
                        //window.location.href = "<?=  base_url('baogongFinish/TaskSubmitByJSON?TaskOperNo=')?>"+TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&TaskOperNumber="+TaskOperNumber+"&TaskOperName="+TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=WGHB&FQty="+FQty;
                        $.ajax({
                            type:"GET",
                            url:'<?=base_url("baogongFinish/TaskSubmitByJSON?TaskOperNo=")?>'+TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&TaskOperNumber="+TaskOperNumber+"&TaskOperName="+TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=WGHB&FQty="+FQty,
                            dataType: "json",
                            success:function(data){
                                window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                        alert(XMLHttpRequest.status);
                                        alert(XMLHttpRequest.readyState);
                                        alert(textStatus);
                                        alert("您输入的信息有误，请重新确认或联系管理员！");
                            }
                        })
                    }else{
                        $("#num").val(''); 
                        alert("请您输入正确的报工数字！");
                    }
                });
                //质检汇报单个汇报
                $(".submitCheck").one("click",function(){
                    var TaskOperNo     = $("#TaskOperNo").val();
                    var LZKNO          = $("#LZKNO").val();
                    var TaskBillNo     = $("#TaskBillNo").val();
                    var TaskOperNumber = $("#TaskOperNumber").val();
                    var TaskOperName   = $("#TaskOperName").val();
                    var UserName       = $("#UserName").val();
                    var UserNo         = $("#UserNo").val();
                    var FQty           = $("#num").val();
                    
                    var BadNum         = $("#badnum_batch").val(); 
                    //异常数量json字符串
                    var badreasonjsonhtml = $("#badreasonjsonhtml").val();
                    //alert('<?=base_url("baogongFinish/TaskQSSubmitByJSONMobile_zhijian?TaskOperNo=")?>'+TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&TaskOperNumber="+TaskOperNumber+"&TaskOperName="+TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=ZJHB&FQty="+FQty+"&BadNum="+BadNum+"&badreasonjsonhtml="+badreasonjsonhtml);
                    //console.log('<?=base_url("baogongFinish/TaskQSSubmitByJSONMobile_zhijian?TaskOperNo=")?>'+TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&TaskOperNumber="+TaskOperNumber+"&TaskOperName="+TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=ZJHB&FQty="+FQty+"&BadNum="+BadNum+"&badreasonjsonhtml="+badreasonjsonhtml);
                    if(!isNaN(FQty)){
                        $.ajax({
                            type:"GET",
                            url:'<?=base_url("baogongFinish/TaskQSSubmitByJSONMobile_zhijian?TaskOperNo=")?>'+TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&TaskOperNumber="+TaskOperNumber+"&TaskOperName="+TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=ZJHB&FQty="+FQty+"&BadNum="+BadNum+"&badreasonjsonhtml="+badreasonjsonhtml,
                            dataType:'json',
                            success:function(data){
                                //console.log(data);
                                window.location.href = "<?=  base_url('baogongFinish/result?type=')?>"+data.type+"&username="+data.username+"&userno="+data.userno+"&resMsg="+data.resMsg;
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                        alert(XMLHttpRequest.status);
                                        alert(XMLHttpRequest.readyState);
                                        alert(textStatus);
                                        alert("您输入的信息有误，请重新确认或联系管理员！");
                            }
                        })
                        //window.location.href = "<?=  base_url('baogongFinish/TaskSubmitByJSON?TaskOperNo=')?>"+TaskOperNo+"&LZKNO="+LZKNO+"&TaskBillNo="+TaskBillNo+"&TaskOperNumber="+TaskOperNumber+"&TaskOperName="+TaskOperName+"&UserName="+UserName+"&UserNo="+UserNo+"&HBType=ZJHB&FQty="+FQty;
                     }else{
                         $("#num").val('');
                        alert("请您输入正确的报工数字！");
                     }
                });
                $(".returnHomePage").click(function(){
                    var UserNo = $("#UserNo").val();
                    window.location.href = "<?=  base_url('baogong/back?UserNo=')?>"+UserNo;
                })
             })
             
   </script>
</html>